#include "selectcpp_c.h"
#ifdef TIME_C_C1_CPP
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <memory.h>

#include <WinSock2.h>
#include <WS2tcpip.h>
#include <windows.h>

using namespace std;

int main(int argc, char *argv[]){
	WSAData wsaData;
	WSAStartup(MAKEWORD(2, 2), &wsaData);

	SOCKET sockfd;
	int n;
	char recvline[101];
	sockaddr_in servaddr;

	if (argc != 2){
		printf("no addr");
		exit(0);
	}

	if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET){
		printf("socket error");
		exit(0);
	}

	memset(&servaddr, 0, sizeof(servaddr));
	servaddr.sin_family = AF_INET;
	servaddr.sin_port = htons(13);
	if (inet_pton(AF_INET, argv[1], &servaddr.sin_addr) <= 0){
		printf("invalid addr");
		exit(0);
	}
	if (connect(sockfd, reinterpret_cast<sockaddr*>(&servaddr), sizeof(servaddr)) < 0){
		printf("connect addr");
		exit(0);
	}

	while ((n = recv(sockfd, recvline, 100, 0))>0){
		recvline[n] = 0;
		if (fputs(recvline, stdout) == EOF){
			printf("fputs addr");
			exit(0);
		}
	}
	return 0;
}
#endif
